//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.枚举右_维护左;

import java.util.HashMap;

public class demo_2364 {
    public demo_2364() {
    }

    public long countBadPairs(int[] nums) {
        int n = nums.length;
        HashMap<Integer, Integer> cnt = new HashMap();
        long count = (long)n * (long)(n - 1) / 2L;

        for(int j = 0; j < n; ++j) {
            int num = j - nums[j];
            int goodNum = (Integer)cnt.getOrDefault(num, 0);
            count -= (long)goodNum;
            cnt.put(num, goodNum + 1);
        }

        return count;
    }
}
